lets_plot.layer_tooltips¶
-
class
lets_plot.layer_tooltips¶ Configure tooltips.
Note
Set tooltips=’none’ to hide tooltips from this layer.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) data = { 'id': np.arange(n), 'x': np.random.normal(size=n), 'y': np.random.normal(size=n), 'c': np.random.choice(['a', 'b'], size=n), 'w': np.random.randint(1, 11, size=n) } ggplot(data, aes('x', 'y')) + \ geom_point(aes(color='c', size='w'), \ tooltips=layer_tooltips().line('@c "@id"') .line('---') .format('@y', '.2f') .line('(x, y)|(^x, @y)') .line('@|@w')) + \ scale_size(range=[2, 4])
1 2 3 4 5 6 7 8 9 10 11 12
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) data = { 'x': np.random.normal(size=n), 'y': np.random.normal(size=n), 'c': np.random.randint(10, size=n) } ggplot(data, aes('x', 'y')) + \ geom_point(aes(color='c'), tooltips='none')
-
__init__()¶ Initialize self.
-
as_dict()¶ Returns the dictionary of all properties of the object.
- Returns
Dictionary of properties.
- Return type
dict
Examples
1 2 3 4 5 6 7
from lets_plot import * LetsPlot.setup_html() layer_tooltips().format('@x', '.2f')\ .line('@x @y')\ .line('^fill')\ .color('black')\ .as_dict()
{'tooltip_formats': [{'field': '@x', 'format': '.2f'}], 'tooltip_lines': ['@x @y', '^fill'], 'tooltip_anchor': None, 'tooltip_min_width': None, 'tooltip_color': 'black'}
-
format(field=None, format=None)¶ Defines the format for displaying the value. This format will be applied to the mapped value in the default tooltip or to the corresponding value specified in the ‘line’ template.
- Parameters
field (str) – Name of an aesthetic or variable that would be formatted. The field name starts with a ‘^’ prefix for aesthetics, the variable name starts with a ‘@’ prefix or without any prefix.
format (str) – Formatting specification. The format contains a number format (‘1.f’) or a string template (‘{.1f}’). The numeric format for non-numeric value will be ignored. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.
- Returns
Layer tooltips specification.
- Return type
layer_tooltips
Note
It’s possible to set the format for all positional aesthetics:
field=’^X’ - for all positional x,
field=’^Y’ - for all positional y.
Note
The string template in format will allow to change lines for the default tooltip without line specifying. Also the template will change the line for outliers. Aes and var formats are not interchangeable, i.e. var format will not be applied to aes, mapped to this variable.
Note
For more info see the formatting reference.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) data = { 'a': np.random.normal(size=n), 'b': np.random.normal(size=n), 'c': np.random.choice(['X', 'Y'], size=n), 'd': np.random.uniform(size=n), 'e': np.random.randint(100, size=n) } ggplot(data, aes('a', 'b')) + \ geom_point(aes(shape='c', size='e', color='d'), show_legend=False, \ tooltips=layer_tooltips().format(field='a', format='.1f')\ .format('^y', '.1f')\ .line('(@a, ^y)')\ .format('c', '{{{}}}')\ .line('@|@c')\ .format('^color', '≈ {.2f}')\ .line('@|^color')\ .format('e', '{}%')\ .line('e|@e')) + \ scale_size(range=[2, 4])
1 2 3 4 5 6 7 8 9 10 11 12 13
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 50 np.random.seed(42) data = { 'v': np.random.normal(size=n), 'c': np.random.choice(['a', 'b', 'c'], size=n), } ggplot(data, aes('c', 'v')) + \ geom_boxplot(tooltips=layer_tooltips().format('^Y', '.4f')\ .format('^ymin', 'min y: {.2f}')\ .format('^ymax', 'max y: {.2f}'))
-
line(value)¶ Line to show in the tooltip. Adds a line template to the tooltip with a label.
- Parameters
value (str) – Enriched string which becomes one line of the tooltip.
- Returns
Layer tooltips specification.
- Return type
layer_tooltips
Note
Variables and aesthetics can be accessed via special syntax:
^color for aes,
@x for variable,
@{x + 1} for variable with spaces in the name,
@{x^2 + 1} for variable with spaces and ‘^’ symbol in the name,
@x^2 for variable with ‘^’ symbol in its name.
A ‘^’ symbol can be escaped with a backslash, a brace character in the literal text - by doubling:
‘x^2’ -> “x^2”
‘{{x}}’ -> “{x}”
The specified ‘line’ for outlier will move it to the general multi-line tooltip. The default tooltip has a label before the value, usually containing the name of the mapped variable. It has its own behaviour, like blank label for axis aesthetics. This default label can be set in template using a pair of symbols ‘@|’. The label can be overridden by specifying a string value before ‘|’ symbol. Within the tooltip line the label is left-aligned, the string formed by template is right-aligned. If a label is not specified, the string will be centered in the tooltip.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 14
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) x = np.linspace(-3, 3, n) y = 9 - x ** 2 + np.random.normal(scale=.3, size=n) data = {'x': x, '9 - x^2': y} ggplot(data) + \ geom_point(aes('x', '9 - x^2'), \ tooltips=layer_tooltips().format('x', '.3f')\ .line('x = @x')\ .format('9 - x^2', '.3f')\ .line('9 - x\^2 = @{9 - x^2}'))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) data = { 'x': np.random.normal(size=n), 'y': np.random.normal(size=n), 'c': np.random.choice(['X', 'Y'], size=n), 'p': np.random.uniform(size=n), 'w': np.random.randint(100, size=n) } ggplot(data, aes('x', 'y')) + \ geom_point(aes(shape='c', size='w', color='p'), show_legend=False, \ tooltips=layer_tooltips().format('x', '.2f')\ .format('y', '.2f')\ .line('(^x, ^y)')\ .line('|^shape')\ .line('@|^color')\ .line('w|^size')) + \ scale_size(range=[2, 4])
-
anchor(value)¶ Specifies a fixed position for a general tooltip.
- Parameters
value ({‘top_left’, ‘top_center’, ‘top_right’, ‘middle_left’, ‘middle_center’, ‘middle_right’, ‘bottom_left’, ‘bottom_center’, ‘bottom_right’}) – Type of the tooltip anchoring.
- Returns
Layer tooltips specification.
- Return type
layer_tooltips
Examples
1 2 3 4 5 6 7 8 9 10
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) x = np.random.normal(size=n) y = np.random.normal(size=n) ggplot({'x': x, 'y': y}, aes('x', 'y')) + \ geom_point(tooltips=layer_tooltips().line('(^x, ^y)')\ .anchor('top_center'))
-
min_width(value)¶ Minimum width of the general tooltip.
- Parameters
value (int) – Minimum width value.
- Returns
Layer tooltips specification.
- Return type
layer_tooltips
Examples
1 2 3 4 5 6 7 8 9 10
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) x = np.random.normal(size=n) y = np.random.normal(size=n) ggplot({'x': x, 'y': y}, aes('x', 'y')) + \ geom_point(tooltips=layer_tooltips().line('(^x, ^y)')\ .min_width(200))
-
color(value)¶ The color for the general tooltip.
- Parameters
value (str) – Color of the tooltip.
- Returns
Layer tooltips specification.
- Return type
layer_tooltips
Examples
1 2 3 4 5 6 7 8 9 10
import numpy as np from lets_plot import * LetsPlot.setup_html() n = 100 np.random.seed(42) x = np.random.normal(size=n) y = np.random.normal(size=n) ggplot({'x': x, 'y': y}, aes('x', 'y')) + \ geom_point(tooltips=layer_tooltips().line('(^x, ^y)')\ .color('magenta'))
-
props()¶ Returns the dictionary of all properties of the object in their initial form.
- Returns
Dictionary of properties.
- Return type
dict
Examples
1 2 3 4
from lets_plot import * LetsPlot.setup_html() p = ggplot({'x': [0], 'y': [0]}) + geom_point(aes('x', 'y')) p.props()
{'data': {'x': [0], 'y': [0]}, 'mapping': <lets_plot.plot.core.FeatureSpec at 0x99ecd88>, 'data_meta': {}}
-